const { resolve } = require('path')
// 生成html文件的插件
const HtmlPlugin = require('html-webpack-plugin')
// 克隆public下面除index.html文件以外的所有其他静态文件
const CopyPlugin = require('copy-webpack-plugin')
// 生产环境
module.exports = {
  entry: './src/index.js',
  output: {
    filename: './js/app.js',
    path: resolve(__dirname, '../build'),
  },
  mode: 'production',
  plugins: [
    new HtmlPlugin({
      template: './public/index.html',
    }),
    new CopyPlugin({
      patterns: [
        {
          from: 'public',
          to: resolve(__dirname, '../build'),
          globOptions: {
            // htmlplug已经处理过index.html了. copyplug不要再处理index.html,否则无法打包
            ignore: ['**/index.html'],
          },
        },
      ],
    }),
  ],
}
